#!/usr/bin/env python
# coding:utf-8


import unittest
from sql_rice.tools.ricer import DSLRicer
from sql_rice.utils import TempFile


class TestDSLRicer(unittest.TestCase):

    def test_conf_display(self):
        dsr = DSLRicer()
        dsr.parse_line('display form')
        self.assertTrue('display' in dsr.config)
        self.assertTrue(dsr.config['display'] == 'form')

    def test_load_ref(self):
        dsr = DSLRicer()
        with TempFile('select rut from tabla') as temp:
            dsr.parse_line('select ref "%s"' % temp.path)
        self.assertEquals(dsr.config['select'], 'select rut from tabla')

    def test_read_inline(self):
        dsr = DSLRicer()
        dsr.parse_line('select begin')
        dsr.parse_line('select rut, nombre, datos')
        dsr.parse_line('from tabla')
        dsr.parse_line('where rut=:rut;')
        dsr.parse_line('end')
        self.assertEquals(dsr.config['select'], 'select rut, nombre, ' +
                          'datos\nfrom tabla\nwhere rut=:rut;')

    def test_unknow_command(self):
        dsr = DSLRicer()
        dsr.parse_line('ruledb hsk')
        dsr.parse_line('select begin')
        dsr.parse_line('select rut from tabla')
        dsr.parse_line('end')
        self.assertEqual(dsr.config['select'], 'select rut from tabla')
